home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Internet / WWW / Perl_WWW_Utilities / MHonArc / lib / mhtxtplain.pl < prev    next >
Encoding:
Perl Script  |  1996-01-19  |  2.2 KB  |  60 lines

  1. ##---------------------------------------------------------------------------##
  2. ##  File:
  3. ##      mhtxtplain.pl
  4. ##  Author:
  5. ##      Earl Hood       ehood@convex.com
  6. ##  Date:
  7. ##    Fri Jan 19 17:22:27 CST 1996
  8. ##  Description:
  9. ##    Library defines routine to filter text/plain body parts to HTML
  10. ##    for MHonArc.
  11. ##    Filter routine can be registered with the following:
  12. ##              <MIMEFILTERS>
  13. ##              text/plain:m2h_text_plain'filter:mhtxtplain.pl
  14. ##              </MIMEFILTERS>
  15. ##---------------------------------------------------------------------------##
  16. ##    MHonArc -- Internet mail-to-HTML converter
  17. ##    Copyright (C) 1995    Earl Hood, ehood@convex.com
  18. ##
  19. ##    This program is free software; you can redistribute it and/or modify
  20. ##    it under the terms of the GNU General Public License as published by
  21. ##    the Free Software Foundation; either version 2 of the License, or
  22. ##    (at your option) any later version.
  23. ##
  24. ##    This program is distributed in the hope that it will be useful,
  25. ##    but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. ##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  27. ##    GNU General Public License for more details.
  28. ##
  29. ##    You should have received a copy of the GNU General Public License
  30. ##    along with this program; if not, write to the Free Software
  31. ##    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  32. ##---------------------------------------------------------------------------##
  33.  
  34.  
  35. package m2h_text_plain;
  36.  
  37. $Url     = '(http://|ftp://|afs://|wais://|telnet://|gopher://|' .
  38.             'news:|nntp:|mid:|cid:|mailto:|prospero:)';
  39. $UrlExp  = $Url . q%[^\s\(\)\|<>"']*[^\.;,"'\|\[\]\(\)\s<>]%;
  40. $HUrlExp = $Url . q%[^\s\(\)\|<>"'\&]*[^\.;,"'\|\[\]\(\)\s<>\&]%;
  41.  
  42. ##---------------------------------------------------------------------------
  43. ##    Filter entitizes special characters, and converts URLs to
  44. ##    hyperlinks.
  45. ##
  46. sub filter {
  47.     local($header, *fields, *data, $isdecode, $args) = @_;
  48.     local($nourl) = ($'NOURL || ($args =~ /nourl/i));
  49.  
  50.     $data =~ s%\&%\&%g;
  51.     $data =~ s%<%\<%g;
  52.     $data =~ s%>%\>%g;
  53.  
  54.     ## Convert URLs to hyperlinks
  55.     $data =~ s%($HUrlExp)%<A HREF="$1">$1</A>%gio  unless $nourl;
  56.     ("<PRE>\n" . $data . "</PRE>\n");
  57. }
  58.  
  59. 1;
  60.